<?php

/**
 * @fileoverview    feed输出工具
 * @author          xinhua
 * @date            Feb  02 11:31:49 CST 2012
 * @copyright       sina meila
 *
 */

class ml_tool_feedOutput
{

    static public function parse(&$pin_data){


        $pin_data['time'] = ml_tool_standardShow::time($pin_data['ctime']);
        $pin_data['price'] = ml_tool_standardShow::rmb_price($pin_data['gd_price']);
        $pin_data['content'] = ml_tool_expression::haveExpressionImg(Tool_string::un_html($pin_data['content']));
        $pin_data['title'] = Tool_string::un_html($pin_data['gd_title']);
        $pin_data['userurl']=ml_tool_picid::pid2url($pin_data['uid'],ML_HEADER_PICSIZE_30,ML_PICTYPE_HEADER);//个人头像


    }
    static $finalHtml=array();

    static public function parseFeed(&$data,$ifme){

        $oBizAtnick = new ml_biz_user_atNick();

        foreach ($data as &$value) {
            
            $value['time']=ml_tool_standardShow::time($value['ctime']);
            $value['from']="来自网站";
            $value['nick'] = Tool_string::un_html($value['nick']);
            $value['portrait'] = ml_tool_picid::uid2portrait($value['uid'] , 'sml');
            
            
            //格式化@昵称
            $controller = ml_factory::get_controller();
            $visitor = $controller->get_visitor();
            if($visitor['uid'] == $value['uid']){
                $value['ifme'] = true;
            }else {    $value['ifme'] = false; }
            
            if($value['is_likeme'])
            $value['ifme']=$ifme;
            
            $content = $oBizAtnick->start($value['content']);
            $content = Tool_string::un_html($content);
            $value['real_content'] = $content;
            $content = ml_tool_expression::haveExpressionImg($content);
            $value['content'] = $oBizAtnick->over($content);

            if(!empty($value['quote']['content']))
            $value['quote']['content']= ml_tool_formatContent::format_content($value['quote']['content']);
                
            switch($value['type']){

                case ML_FEED_TYPE_PUB_SHORT:
                    self::$finalHtml[]=ml_tool_template::parseModTpl($value, '/feed::short');
                    break;

                case ML_FEED_TYPE_PUB_DOTEY:
                case ML_FEED_TYPE_PUB_PIC:
                    $value['picurl']=ml_tool_picid::pid2url($value['pic_id'],ML_USER_PICSIZE_FEED,ML_PICTYPE_CONTENT);//二三参数待定！！！！！
                    $value['picurl_big']=ml_tool_picid::pid2url($value['pic_id'],ML_USER_PICSIZE_SHOW,ML_PICTYPE_CONTENT);
                    $value['gd_title'] = Tool_string::un_html($value['gd_title']);
                    self::$finalHtml[]=ml_tool_template::parseModTpl($value, '/feed::dotey');

                    break;

//                case ML_FEED_TYPE_PUB_PIC:
//                case 
//                    $value['picurl']=ml_tool_picid::pid2url($value['pic_id'],ML_USER_PICSIZE_FEED,ML_PICTYPE_CONTENT);//二三参数待定！！！！！
//                    $value['picurl_big']=ml_tool_picid::pid2url($value['pic_id'],ML_USER_PICSIZE_SHOW,ML_PICTYPE_CONTENT);
//                    self::$finalHtml[]=ml_tool_template::parseModTpl($value, '/feed::pic');
//                    break;

                case ML_FEED_TYPE_MOD_DEC:
                    self::$finalHtml[]=ml_tool_template::parseModTpl($value, '/feed::dec');
                    break;

                case ML_FEED_TYPE_ATTITUDE:

                    $value['picurl']=ml_tool_picid::pid2url($value['quote']['pic_id'],ML_USER_PICSIZE_FEED,ML_PICTYPE_CONTENT);
                    $value['picurl_big']=ml_tool_picid::pid2url($value['quote']['pic_id'],ML_USER_PICSIZE_SHOW,ML_PICTYPE_CONTENT);
                    $value['quote']['gd_title'] = Tool_string::un_html($value['quote']['gd_title']);
                    $value['is_pic']=empty($value['quote']['gd_info']['gd_url'])?true:false;
                    self::$finalHtml[]=ml_tool_template::parseModTpl($value, '/feed::attitude_dotey');
                    break;

                case ML_FEED_TYPE_MOD_TAG:
                    $value['content']=explode(",", $value['content']);
                    self::$finalHtml[]=ml_tool_template::parseModTpl($value, '/feed::tag');
                    break;
                case ML_FEED_TYPE_REPOST_COLLECTION:
                        
                    $value['picurl']=ml_tool_picid::pid2url($value['quote']['pic_id'],ML_USER_PICSIZE_FEED,ML_PICTYPE_CONTENT);
                    $value['picurl_big']=ml_tool_picid::pid2url($value['quote']['pic_id'],ML_USER_PICSIZE_SHOW,ML_PICTYPE_CONTENT);
                    $value['quote']['gd_title'] = Tool_string::un_html($value['quote']['gd_title']);
                    $value['is_pic']=empty($value['quote']['gd_info']['gd_url'])?true:false;
                    self::$finalHtml[]=ml_tool_template::parseModTpl($value, '/feed::repost');
                    break;

            }
        }

        return self::$finalHtml;
    }

    /**
     *根据表态生成title文案，不知道放在这里合适不~~~~
     *
     */
    static function makeTitle($att){
        $rs='';
        switch ($att) {
            case '0':
                $rs="可以有";
                break;
            case '1':
                $rs="长草了";
                break;
            case '2':
                $rs="不感冒";
                break;
            case '3':
                $rs="喜欢";
                break;
                    
        }
        return $rs;
    }
}